/*
** xfunc2.c for irc in /home/billey_b/projet/my_irc
** 
** Made by Bastien Billey
** Login   <billey_b@epitech.net>
** 
** Started on  Fri Apr 13 12:55:54 2012 Bastien Billey
** Last update Tue Apr 17 15:07:46 2012 anthony jean
*/

#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include	"server.h"

ssize_t	xread(int fd, void *buf, size_t count)
{
  int	n;

  n = read(fd, buf, count);
  if (n < 0)
    {
      perror("read");
      exit(0);
    }
  return n;
}

ssize_t	xwrite(int fd, const void *buf, size_t count)
{
  int	n;

  n = write(fd, buf, count);
  if (n < 0)
    {
      perror("write");
      exit(0);
    }
  return n;

}

int	xopen(const char *pathname, int flags)
{
  int	fd;

  fd = open(pathname, flags);
  if (fd < 0)
    {
      perror("open");
      exit(0);
    }
  return fd;
}

void	*xmalloc(size_t size)
{
  void	*p;

  p = malloc(size);
  if (p == 0)
    {
      perror("malloc");
      exit(EXIT_FAILURE);
    }
  return p;
}

void	xfree(void *ptr)
{
  if (ptr != NULL)
    free(ptr);
  else
    exit(EXIT_FAILURE);
}
